import axios from 'axios'
import store from '@/store'

const instance = axios.create({
  baseURL: 'http://toutiao.itheima.net'
})

instance.interceptors.request.use(function (config) {
  const TOKEN = store.state.user.token

  if(TOKEN) {
    config.headers.Authorization = `Bearer ${TOKEN}`
  }

  return config
}, function (error) {
  return Promise.reject(error)
})

export default instance
